<%@page import="edu.hcmus.sow.domain.Folder"%>
<%@page import="edu.hcmus.sow.domain.security.CustomUser"%>
<%@page import="org.springframework.security.core.context.SecurityContext"%>
<%@page import="org.springframework.security.core.Authentication"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="edu.hcmus.sow.service.DocumentService"%>
<%@page import="edu.hcmus.sow.domain.Repository"%>
<%@page import="java.util.List"%>
<%@ page language="java" isELIgnored="false" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:directive.include file="/WEB-INF/sitemesh-decorators/include.jsp" />
<fmt:setBundle basename="bundles.application-resources" />

<script type="text/javascript">
   Wicket.Event.add(window, "domready", function(event) {
      $('#documents').click(function() {
         $('#documentsContainer').slideToggle(250, function() {
            $('.listMyRecentViewedCubesPanel_wrapper select').selectbox();
         });
         if ($(this).parent('li').hasClass('hover'))
            $(this).parent('li').removeClass('hover');
         else
            $(this).parent('li').addClass('hover');
      });
   });
</script>
<script type="text/javascript">
   Wicket.Event.add(window, "domready", function(event) {
      var myTimeout = null;
      $('#documentsContainer').bind("mouseleave", function() {
         myTimeout = window.setTimeout(function() {
            $("#documentsContainer").slideUp(200);
            $('#documents').parent('li').removeClass('hover');
         }, 750);
      });
      $('#documentsContainer').bind("mouseenter", function() {
         window.clearTimeout(myTimeout);
      });
      ;
   });
</script>
<script type="text/javascript">
   Wicket.Event.add(window, "domready", function(event) {
      $('#project').click(function() {
         $('#projectContainer').slideToggle(250, function() {
            $('.listMyRecentViewedCubesPanel_wrapper select').selectbox();
         });
         if ($(this).parent('li').hasClass('hover'))
            $(this).parent('li').removeClass('hover');
         else
            $(this).parent('li').addClass('hover');
      });
   });
</script>
<script type="text/javascript">
   Wicket.Event.add(window, "domready", function(event) {
      var myTimeout = null;
      $('#projectContainer').bind("mouseleave", function() {
         myTimeout = window.setTimeout(function() {
            $("#projectContainer").slideUp(200);
            $('#project').parent('li').removeClass('hover');
         }, 750);
      });
      $('#projectContainer').bind("mouseenter", function() {
         window.clearTimeout(myTimeout);
      });
      ;
   });
</script>

<div id="menuup" class="search_header">
   <div class="search userDefinedBg">
      <span>
         <form id="searchForm" name="searchForm" method="post" action="">
            <div style="width: 0px; height: 0px; position: absolute; left: -100px; top: -100px; overflow: hidden">
               <input type="hidden" name="searchForm" id="searchForm" />
            </div>
            <input type="text" class="searchFormPanel_input_text" value="" name="search" /> <span
               class="searchFormInputWrapper userDefinedBg">
               <button type="submit" class="searchFormPanel_input_image" value="" name="submit" id="submit">
                  <span>Search</span>
               </button>
            </span>
         </form>
      </span>
   </div>

   <div class="menuup_left">
      <ul class="ul_menuup">
         <li class="active"><a href="<c:url value="/dashboard" />">Dashboard</a></li>
         <li id="cubeTab" class="selected"><a class="tab" href="javascript:;" id="documents">Documents</a>
            <div class="tab_subcontent">
               <span class="cubeCont" style="display: none;" id="documentsContainer">
                  <div>
                     <div class="listMyRecentViewedCubesPanel_header"></div>
                     <div class="listMyRecentViewedCubesPanel">
                        <div class="listMyRecentViewedCubesPanel_wrapper">
                           <div class="listMyRecentViewedCubesPanel_projectLinkC_wrapper">
                              <!-- repositories list -->
                              <%
                                 Authentication auth = ((SecurityContext)session.getAttribute("SPRING_SECURITY_CONTEXT")).getAuthentication();
                                 //System.out.println(auth);
                                 int clientID = ((CustomUser) auth.getPrincipal()).getClientID();
                                 //System.out.println(clientID);
                                 WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
                                 DocumentService documentService =  (DocumentService) wac.getBean("documentService");
                                 List<Folder> repositories = documentService.getAuthorizedRepositories(clientID);
                                 for(Folder repo : repositories){
                              %>
                              <div class="projectLinkC userDefinedColor">
                                 <a style="text-align: left" href="${pageContext.request.contextPath}/repository/<%=repo.getId() %>"
                                    class="projectLink">
                                    <div><%=repo.getName() %></div> <span class="description"><%=repo.getDescription() %></span>
                                 </a>
                              </div>
                              <%} %>
                              <!-- end repositories list -->
                           </div>
                        </div>
                     </div>
                     <div class="listMyRecentViewedCubesPanel_bottom"></div>
                  </div>
               </span>
            </div></li>
         <li id="cubeTab" class="selected"><a class="tab" href="javascript:;" id="project">Projects</a>
            <div class="tab_subcontent">
               <span class="cubeCont" style="display: none;" id="projectContainer">
                  <div>
                     <div class="listMyRecentViewedCubesPanel_header"></div>
                     <div class="listMyRecentViewedCubesPanel">
                        <div class="listMyRecentViewedCubesPanel_wrapper">
                           <div class="listMyRecentViewedCubesPanel_projectLinkC_wrapper">
                              <div class="projectLinkC userDefinedColor">
                                 <a style="text-align: left"
                                    href="https://nbphuong88.glasscubes.com/cube/dashboard/48887" class="projectLink">
                                    <div>Project A</div> <span class="description">aa</span>
                                 </a>
                              </div>
                              <div class="projectLinkC userDefinedColor">
                                 <a style="text-align: left"
                                    href="https://nbphuong88.glasscubes.com/cube/dashboard/48887" class="projectLink">
                                    <div>Project B</div> <span class="description">bbb</span>
                                 </a>
                              </div>
                              <div class="projectLinkC userDefinedColor">
                                 <a style="text-align: left"
                                    href="https://nbphuong88.glasscubes.com/cube/dashboard/48887" class="projectLink">
                                    <div>Project C</div> <span class="description">cccc</span>
                                 </a>
                              </div>
                           </div>
                        </div>
                     </div>
                     <div class="listMyRecentViewedCubesPanel_bottom"></div>
                  </div>
               </span>
            </div></li>
         <li><a href="my_task.html">Calendar</a></li>
         <li><a href="my_task.html">Discussion</a></li>
      </ul>
   </div>
   <div class="mneuup_right">
      <div class="down_up"></div>
   </div>
</div>